﻿
@{
    ViewBag.Title = "addapp";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<link href="~/Content/css/_form.css" rel="stylesheet" />
<link href="~/Content/css/AddCase.css" rel="stylesheet" />
<form id="addapp" method="post" runat="server" action=""enctype="multipart/form-data">
    <div id="pagecontent" class="row from-conent ">
        <div class="input-group ">
            <label for="EDTIONCODE" class="col-sm-3 control-label"><i class="must">*</i>版本号:</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="EDTIONCODE" name="EDTIONCODE" v-model="APPINFO.EDTIONCODE" autocomplete="off" maxlength="20" required>
            </div>
        </div>
        <div class="input-group ">
            <label for="EDTIONCODE" class="col-sm-3 control-label"><i class="must">*</i>APP版本信息:</label>
            <div class="col-sm-9">
                <input type="text" class="form-control" id="APPVERSION" name="APPVERSION" v-model="APPINFO.APPVERSION" autocomplete="off" maxlength="20" required>
            </div>
        </div>

        <div class="input-group ">
            <label class="col-sm-3 control-label"><i class="must">*</i>上传apk:</label>
            <div class="col-sm-9">
                <input id="file" type="file" runat="server" />
                @*<img src="~/Content/images/附件管理.png" v-on:click="uploadFile();" />*@
            </div>
        </div>

        <div class="input-group ">
            <div class="col-sm-4"></div>
            <div class="col-sm-2 from-left-btn">
                <input type="button" class="form-control btn " style="background-color:#1CC9B5;color:#FFFFFF;" value="提交" id="saveForm" v-on:click="saveForm" />
            </div>
            <div class="col-sm-2 from-right-btn">
                <input type="button" class="form-control btn " style="background-color:#1890ff;color:#FFFFFF; " value="重置" id="resetForm" v-on:click="resetForm" />
            </div>
        </div>
        <div style="display:none">
            <input id="Id" type="text" name="Id" v-model="APPINFO.Id" />
        </div>
    </div>
</form>
@section scripts{
    <script>
        
        var user = getCookie("user") // 读取 cookie
        var pass = getCookie("pass") // 读取 cookie
        if (user == null || pass == null) {
            window.location.href = "./Index";
        }
        $.SendPostAjax("./IfLogin", { "user": user, "pass": pass }
            , function (d) {
                if (d != "1") {
                    layer.msg("帐号或密码错误！");
                    window.location.href = "./LoginView";
                }
            });
        var guid;
        new Vue({
            el: "#addapp",
            data: {
                APPINFO: {
                },
                id: Robin.Utils.GetQuery("ID", ""),
            },
            mounted: function () {
                this.initMethod(this.id);
                $('#addapp').slimScroll({
                    height: '400px'
                });
            },
            computed: {

            },
            methods: {
                initMethod: function (id) {
                    $.SendPostAjax("./GetEdtionById", { "id": id }, this.initForm);
                    if (id == "") {
                        var user = localStorage.getItem("user");
                        var result = JSON.parse(user);
                        //this.APPINFO.ADDBY = result.TEAMID;
                        //this.APPINFO.CREATETEAMNAME = result.TEAMNAME;
                    }
                }
                ,
                initForm: function (d) {
                    var that = this;
                    if (d.Success) {
                        that.APPINFO = d.Result;
                    }
                },
                refreshFrom: function (data) {
                    var that = this;
                    if (data.Result.status == "0") {
                        that.initMethod(that.id);
                    }
                },
                saveForm: function () {
                    that = this;
                   
                    var files = document.getElementById("file").files;
                    var formdata = new FormData();
                  
                    var a= $("#file").val();
                    debugger
                    if (Robin.Utils.GetQuery("ID", "") == "" && $("#file").val()=="") {
                        layer.msg("请先上传文件", { icon: 2 });
                        return false;
                    }
                    var res = ValidatorFromInit("addapp").form();
                    if (res) {
                        formdata.append("files", files[0]);
                        formdata.append("APPVERSION", this.APPINFO.APPVERSION);
                        formdata.append("Id", this.APPINFO.Id);
                        formdata.append("EDTIONCODE", this.APPINFO.EDTIONCODE);
                        debugger
                        var data = this.APPINFO;
                        SaveFormData("./AddEditonApi", formdata, "", that.refreshFrom, true, parent.appVm.initTable);
                        //setTimeout(function () {    //关闭窗口
                        //    parent.closeAllJsPanel();
                        //}, 2000);
                    }
                    return false;
                },
                resetForm: function () {
                    this.initMethod(this.id);
                }
                //,
                //uploadFile: function () {
                //    guid = this.APPINFO.Id;
                //    var type = '巡检apk文件';
                //    var url = './Filemanager/callfilemanager.html?id=' + guid + '&type=' + type +'&number=1';
                //    parent.commonJsPanel("附件管理", url, 850, 490, null, 1, false);
                //}
            }
        });
    </script>
}

